package jmine.tec.persist.schema.association.list.jointable;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.annotation.Comment;
import jmine.tec.persist.annotation.Comments;
import jmine.tec.persist.annotation.Index;
import jmine.tec.persist.annotation.Indexes;
import jmine.tec.persist.annotation.UniqueConstraint;
import jmine.tec.persist.schema.association.ValueEntity;

import org.hibernate.annotations.IndexColumn;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;

@Entity
@Alias("OWNER")
@Table(name = "OWNER")
@Documentation("TABELA OWNER")
@SequenceGenerator(name = "SEQ_OWNER", sequenceName = "SEQ_OWNER")
public class ListOwnerEntity extends PersistableBusinessObject {

    private Long id;

    private List<ValueEntity> associations;

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(generator = "SEQ_OWNER")
    @Column(name = "COD_OWNER", precision = 17, nullable = false)
    @Documentation("CODIGO OWNER")
    public Long getId() {
        return this.id;
    }

    /**
     * @return the associations
     */
    @Indexes({ @Index(suffix = "JT_0", columns = "COD_OWNER"), @Index(suffix = "JT_1", columns = "COD_VALUE") })
    @OneToMany
    @Alias("LIST")
    @JoinTable(name = "LIST_ASSOCIATION", joinColumns = @JoinColumn(name = "COD_OWNER", nullable = false), inverseJoinColumns = @JoinColumn(name = "COD_VALUE", nullable = false))
    @UniqueConstraint(suffix = "0", columns = { "COD_VALUE" })
    @IndexColumn(name = "IDX")
    @Comments({ @Comment(table = "LIST_ASSOCIATION", value = "TABELA DE COLLECTION"),
            @Comment(table = "LIST_ASSOCIATION", column = "IDX", value = "COLUNA DE INDICE"),
            @Comment(table = "LIST_ASSOCIATION", column = "COD_OWNER", value = "CODIGO DA ENTIDADE OWNER DA COLLECTION"),
            @Comment(table = "LIST_ASSOCIATION", column = "COD_VALUE", value = "CODIGO DA ENTIDADE VALOR") })
    public List<ValueEntity> getAssociations() {
        return this.associations;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param associations the associations to set
     */
    public void setAssociations(List<ValueEntity> associations) {
        this.associations = associations;
    }
}
